package com.wc.AlgoOJ_train.train3_算法大礼包.c3_贪心.AG0403_涂防晒;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/28 22:41
 * @description http://43.138.190.70:8888/p/AG0403
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2510;
    static int[][] a = new int[N][2];
    static int[][] b = new int[N][2];
    static boolean[] vis = new boolean[N];
    static int n, m;

    /**
     * 贪心一点，大的先给大的用，大的用不完，小的用，所以要倒着来
     */
    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i][0] = sc.nextInt();
            a[i][1] = sc.nextInt();
        }
        for (int i = 1; i <= m; i++) {
            b[i][0] = sc.nextInt();
            b[i][1] = sc.nextInt();
        }
        Arrays.sort(a, 1, n + 1, Comparator.comparingInt(o -> o[0]));
//        Arrays.sort(a, 1, n + 1, Comparator.comparingInt(o -> o[1] - o[0]));
        Arrays.sort(b, 1, m + 1, Comparator.comparingInt(o -> o[0]));

        for (int i = m; i >= 1; i--) {
            for (int j = n; j >= 1; j--) {
                if (!vis[j] && b[i][0] >= a[j][0] && b[i][0] <= a[j][1] && b[i][1] >= 1) {
                    b[i][1]--;
                    vis[j] = true;
                }
            }
        }
        int res = 0;
        for (int i = 1; i <= n; i++) {
            if (vis[i]) res++;
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
